<template>
  <div class="home app-wrapper">
        <div class="lm-swipe">
            <router-link class="tag" to="/invitation"><i class="icon icon-share"></i> 邀请卡</router-link>
            <swiper>
　　            <swiper-slide><img :src="channel.cover" /></swiper-slide>
            </swiper>
        </div>
        <div class="home-desc clearfix mb15">
            <h3 class="pull-left">{{channel.name}}</h3>
            <span class="subtitle-more pull-right">已更新{{channel.live_num}}个直播</span>
        </div>
        <div class="home-main tab">
            <div class="tab-header text-center">
                <div class="tab-header-item"
                    :class="{'active': activeTab === 'topic'}"
                    @click="activeTab = 'topic'"
                ><span>话题列表</span></div>
                <div class="tab-header-item"
                    :class="{'active': activeTab === 'channel'}"
                    @click="activeTab = 'channel'"
                ><span>频道简介</span></div>
            </div>
            <div class="tab-body" ref="scrollerWrapper">
                <mescroll-vue 
                    ref="mescroll" 
                    :up="mescrollUp" 
                    :down="mescrollDown"
                    @init="mescrollInit"
                    class="content-slide"
                >
                <div class="tab-body-item topic-list" 
                    v-show="activeTab === 'topic'"
                >
                    <ul>
                        <router-link
                            class="topic-list-item"
                            v-for="item in lives"
                            :key="item.id"
                            :to="{name:'live', params: {id:item.id}}"
                            tag="li"
                        >
                            <div class="topic-list-thumb relative">
                                <span :class="item.statusColor">{{item.live_status_text}}</span>
                                <img :src="item.cover" alt="">
                            </div>
                            <div class="list-body flex-item">
                                <h4 class="list-body-head">{{item.title}}</h4>
                                <p class="list-body-subinfo"><span>{{item.type_text}}</span><span class="div-line">|</span><time>{{item.start_at}}</time></p>
                                <p class="topic-list-body-count">{{item.fic_num}}人次观看<span><i class="icon icon-msg"></i></span></p>
                            </div>
                        </router-link>
                        <router-link
                            class="topic-list-item"
                            v-for="item in lives"
                            :key="item.id"
                            :to="{name:'live', params: {id:item.id}}"
                            tag="li"
                        >
                            <div class="topic-list-thumb relative">
                                <span :class="item.statusColor">{{item.live_status_text}}</span>
                                <img :src="item.cover" alt="">
                            </div>
                            <div class="list-body flex-item">
                                <h4 class="list-body-head">{{item.title}}</h4>
                                <p class="list-body-subinfo"><span>{{item.type_text}}</span><span class="div-line">|</span><time>{{item.start_at}}</time></p>
                                <p class="topic-list-body-count">{{item.fic_num}}人次观看<span><i class="icon icon-msg"></i></span></p>
                            </div>
                        </router-link>
                    </ul>
                    <div class="all-loaded text-center" v-if="topicsNone">已加载全部</div>
                </div>
                <div class="tab-body-item channel-list" v-show="activeTab === 'channel'">
                  
                  <div class="panel-intro" 
                    v-for="(intro_content,index) in intro"
                    :key="index"
                  >
                    <h3 class="title">{{intro_content.name}}</h3>
                    <div v-html="intro_content.content" class="panel-content"></div>
                  </div>

                    <ul>
                        <li class="channel-list-item">
                            <div class="media clearfix">
                                <div class="media-object pull-left">
                                    <img :src="siteinfo.live_logo" />
                                </div>
                                <div class="media-body">
                                    <h4 class="media-heading">{{siteinfo.live_name}}</h4>
                                </div>
                                <span class="media-option disabled">已关注</span>
                            </div>
                        </li>
                    </ul>
                </div>
                </mescroll-vue>
            </div>
        </div>

        <div class="button-circle-plus button" @click="showNavbar = true"></div>

        <van-popup 
            position="bottom"
            overlay="false"
            overlay-class="app-masker"
            get-container=".app-wrapper"
            v-model="showNavbar"
        >
            <NavActionSheet @hideNavBar="hideNavbar"></NavActionSheet>  
        </van-popup>

        <div class="dialog-prompt text-center" v-if="promptDialogShow">
            <div class="dialog-title">咨询</div>
            <div class="dialog-body">
                <input type="text" placeholder="" class="input-text" v-model="promptContent">
            </div>
            <div class="dialog-options">
                <button type="button" class="buton-cancel" @click.stop="hidePromptDialog">取消</button><button type="button" class="buton-true" @click.stop="submitPromptContent">确定</button>
            </div>
        </div>


  </div>
</template>

<script>
import NavActionSheet from '@/components/NavActionSheet';
import MescrollVue from 'mescroll.js/mescroll.vue';
import TopicItem from '@/components/TopicItem';
import 'swiper/dist/css/swiper.css';
import { swiper, swiperSlide } from 'vue-awesome-swiper';
import {getCateLives, getChannelList} from '@/api';
import {getVideoStatusColor} from '@/utils/function';


export default {
    components: {
        swiper,
        swiperSlide,
        TopicItem,
        MescrollVue,
        NavActionSheet
    },
    props: {},
    data() {
        return {
            // 滚动条
            mescroll: null,
            mescrollDown: {
                isLock: true
            },
            mescrollUp:{
                auto: false,
                callback: this.upCallback,
                noMoreSize: 3,
                onScroll: this.onContentSlideScroll
            },
            topicsNone: false,
            promptDialogShow: false,
            promptContent: '', // 咨询内容
            activeTab: 'topic',
            showNavbar: false,
            channel: {
                cover: '',
                id: '',
                live_num: '',
                intro: ''
            },
            liveMaps: {},
            lives:[],
            siteinfo:{},
            introLists: [
                {
                    id: 1,
                    name: '目睹直播平台',
                    imgSrc: './img/home_intro_img.png',
                    isFollow: true
                },
                {
                    id: 2,
                    name: '目睹直播平台2',
                    imgSrc: './img/home_intro_img.png',
                    isFollow: false
                },
                {
                    id: 3,
                    name: '目睹直播平台3',
                    imgSrc: './img/home_intro_img.png',
                    isFollow: true
                }
            ],
            swiperOption: {
                pagination: {
            　　　　el: '.swiper-pagination'
            　　}
            }
        };
    },
    computed: {},
    methods: {
        hideNavbar(){
            this.showNavbar = false;
        },
        // mescroll组件初始化的回调,可获取到mescroll对象
        mescrollInit (mescroll) {
            this.mescroll = mescroll;  // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
        },  
        onContentSlideScroll(){

        },
        onScrollEnd(pos){
            console.log('onScrollEnd:', pos)
        },
        upCallback(){
            let type = this.activeTab;
            if(this.activeTab === 'topic'){
                getCateLives(++this.liveMaps.current_page).then((response)=>{
                    let livesData = response.data
                    console.log(response)
                    this.lives = [...this.lives, ...livesData.data];
                    this.upSuccessCallback(livesData);
                });
            }
        },
        upSuccessCallback(data){
            console.log('判断信息：', data)
            if(data.current_page === data.last_page || data.current_page === data.total){
                this.topicsNone = true;
            }

            this.mescroll.endSuccess(false);  
        },
        showPromptDialog(){
            this.promptDialogShow = true;
            this.$store.dispatch('setMaskerDisplay', true);
        },
        hidePromptDialog(){
            this.promptDialogShow = false;
            this.$store.dispatch('setMaskerDisplay', false);
        },
        submitPromptContent(){

            console.log(this.promptContent)
            this.hidePromptDialog();
        },
        switchFollowStatus(item){
            setTimeout(()=>{
                item.isFollow = !item.isFollow;
            }, 1500);
        }
    },
    created() {
        getChannelList().then((response)=>{
            if(response.code === 0){
                let result = response.data;

                this.liveMaps = result.lives;
                this.lives =result.lives.data.map((item)=>{
                    item.statusColor = getVideoStatusColor(item.live_status);
                    return item;
                });
                this.channel = response.data.channel;
                this.intro = response.data.intro;
                this.siteinfo = response.data.siteinfo;
            }
        });
    },
    mounted() {},
};
</script>
<style lang="scss" scoped>
@import '@/assets/config.scss';
$swipe-height: 350px;
.lm-swipe {
    height: $swipe-height;
    overflow: hidden;
    position: relative;
    .tag {
        padding: 0 10px;
        position: absolute;
        top: 0;
        right: 0;
        font-size: 24px;
        color: #fff;
        line-height: 2;
        border-radius: 0 0 0 12px;
        background: linear-gradient(#318bff, #103ee7);
        z-index: 5;
        .icon {
            font-size: 32px;
            vertical-align: middle;
            position: relative;
            top: 2px;
        }
    }

    .swiper-slide img {
        width: 100%;
        height: 350px;
    }

    .swiper-pagination-bullet {
        width: 20px;
        height: 20px;
    }
}

.home-desc {
    height: 100px;
    padding: 0 35px;
    line-height: 100px;
    background-color: $bg-white;

    > h3 {
        color: $title-color;
        font-size: 34px;
    }

    .subtitle-more {
        font-size: 26px;
        color: $desc-color;
    }
}

.home-main {
    height: calc(100% - 350px - 100px - 15px);
    background-color: $bg-white;
    .tab-body {
        height: calc(100% - 106px);
        overflow: hidden;
    }

    .content-slide { 
        height: 100%; 
        overflow-y: auto;
    }
}


.topic-list-item {
  display: flex;
  padding: 25px 35px;
  align-items: center;
  position: relative;
  &:after {
    content: '';
    height: 2px;
    position: absolute;
    left: 35px;
    right: 35px;
    bottom: 0;
    background-color: #f0f0f0;
  }

   .topic-list-thumb {
    width: 40%;
    margin-right: 20px;
    position: relative;
    > span {
      position: absolute;
      top: 10px;
      left: 10px;
      padding: 6px 7px 5px;
      font-size: 24px;
      color: #fff;
      line-height: 26px;
      border-radius: 2px;
      &.blue{
        background: #1549eb;
      }

      &.orange {
        background: #fcba2e;
      }
    }
  }
}


.tab-header {
    display: flex;
    align-items: center;
    position: relative;
    &:after {
        content: '';
        position: absolute;
        width: 2px;
        height: 28px;
        background-color: #ddd;
        left: 50%;
        top: 50%;
        transform: translate3d(-50%, -50%, 0)
    }
}

.tab-header-item {
    flex: 1;
    font-size: 30px;
    color: #333;

    span {
        display: inline-block;
        padding: 30px 0 36px;
        position: relative;
    }

    &.active span {

        color: #1549eb;
        &:after{
            width: 100%;
            position: absolute;
            left: 0;
            bottom: 0;
            content: '';
            height: 4px;
            background-color: #1549eb;
        }
    }

}

    .list-body-head {
        font-size: 28px;
        line-height: 36px;
        color: $title-color;
    }

    .topic-list-body-count, .list-body-subinfo {
        font-size: 24px;
        line-height: 2;
        color: #888;
    }

    .div-line{
        margin: 0 20px 0 24px;
    }

.channel-list {
    padding: 0 35px;
    .title {
        height: 90px;
        border-bottom: 1px solid #f0f0f0;
        margin-bottom: 10px;
        line-height: 90px;
        font-size: 30px;
        color: #2a2a2a;
    }
}
.channel-list-item {
    padding: 20px 0;
    position: relative;

    .media {
        display: flex;
        align-items: center;
    }
    .media-object{
        width: 80px;
        height: 80px;
        margin-right: 20px;
        border-radius: 100%;
        overflow: hidden;
        img { 
            width: 100%;
            height: 100%;
            vertical-align: top; 

        }
    }
    .media-body {
        overflow: hidden;
    }
    .media-heading {
        font-size: 28px;
        color: #333;
    }

    .media-option {
        width: 110px;
        height: 54px;
        border: 2px solid #1549eb;
        position: absolute;
        right: 0;
        top: 50%;
        font-size: 24px;
        color: #1549eb;
        text-align: center;
        line-height: 54px;
        border-radius: 27px;
        transform: translateY(-50%);
        &.disabled {
            color: #b6b6b6;
            border: 2px solid #b6b6b6;
        }
    }
}

.button {
    position: fixed;
    width: 100px;
    height: 100px;
    border-radius: 100%;
    bottom: 94px;
    right: 35px;
    background: linear-gradient(#103ee7, #318bff);
    transform: rotate(111deg);
    z-index: 5;
    &:after, &:before {
        content: '';
        background: $bg-white;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate3d(-50%, -50%, 0) rotate(-111deg);
        border-radius: 2px;
    }

    &:after {
        width: 4px;
        height: 40px;

    }

    &:before {
        width: 40px;
        height: 4px;
    }
}


.dialog-prompt {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 560px;
    height: 300px;
    padding-top: 20px;
    font-size: 30px;
    color: #999;
    background-color: #fff;
    border-radius: 16px;
    transform: translate3d(-50%, -50%, 0);
    z-index: 2000;
    .dialog-title {
        line-height: 2;
        color: #333;
    }
    .dialog-body {
        padding:  30px 0;
    }

    .input-text {
        width: 85%;
        height: 80px;
        padding: 0 20px;
        margin-right: 15px;
        border: 1px solid #ccc;
        line-height: 74px;;
        border-radius: 6px;
    }

    .dialog-options {
        height: 80px;
        line-height: 80px;
        position: relative;

        &:before{
            content: '';
            display: block;
            width: 100%;
            height: 2px;
            top: 0;
            background: #ccc;
        }
        &:after {
            content: '';
            display: block;
            height: 80px;
            width: 2px;
            background: #ccc;
            position: absolute;
            top: 0;
            left: 50%;
            margin-left: -1px;
        }

        button {
            width: 50%;
            background-color: transparent;
        }

        .buton-true { color: #1549eb; }
    }

}

.panel-intro {
  margin-bottom: 30px;
  .panel-content {
    font-size: 28px;
    line-height: 2;
  }
}

</style>
